package d5_TCP2;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;

public class ServerReaderThread extends Thread {
    private Socket socket;
    public ServerReaderThread(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {
        InputStream is= null;
        try {
            is = socket.getInputStream();//创建字节输入流
            DataInputStream dis = new DataInputStream(is);//转换为数据输入流
            while (true) {
                try {
                    System.out.println(dis.readUTF());
                } catch (IOException e) {
                    System.out.println(socket.getRemoteSocketAddress()+"line break"+e.getMessage());
                    dis.close();
                    socket.close();
                    break;
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
